package com.frinder.robot.strategy.task.distribute;

import com.frinder.base.strategy.Strategy;
import com.frinder.robot.strategy.task.distribute.biz.DistributeTaskToRobotDistanceStrategy;
import com.frinder.robot.strategy.task.distribute.biz.DistributeTaskToRobotPriorityDistanceStrategy;
import com.frinder.robot.strategy.task.distribute.biz.DistributeTaskToRobotPriorityStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @ClassName DistributeTaskToRobotHandler
 * @Description 分派任务处理器
 * @Author frinder
 * @Date 2019/10/19 14:24
 * @Verion 1.0
 */
@Component
public class DistributeTaskToRobotHandler {

    @Autowired
    private DistributeTaskToRobotPriorityStrategy distributeTaskToRobotPriorityStrategy;

    @Autowired
    private DistributeTaskToRobotDistanceStrategy distributeTaskToRobotDistanceStrategy;

    @Autowired
    private DistributeTaskToRobotPriorityDistanceStrategy distributeTaskToRobotPriorityDistanceStrategy;

    private DistributeTaskToRobotBaseStrategy distributeTaskToRobotBaseStrategy;

    @PostConstruct
    public void post() {
        distributeTaskToRobotBaseStrategy = new DistributeTaskToRobotDistanceStrategy();
        distributeTaskToRobotBaseStrategy
                .register(distributeTaskToRobotPriorityStrategy)
                .register(distributeTaskToRobotDistanceStrategy)
                .register(distributeTaskToRobotPriorityDistanceStrategy);
    }

    @Strategy
    public void handle(DistributeTaskToRobotPayload payload) {
        distributeTaskToRobotBaseStrategy.handle(payload);
    }

}
